package com.example.project.domain.response;

import lombok.AllArgsConstructor;
import lombok.Data;
import org.springframework.http.HttpStatus;

/**
 * 统一响应结果
 */
@Data
@AllArgsConstructor
public class Response<T> {
    private int code;            // HTTP状态码
    private String message;      // 消息
    private T data;              // 数据

    public Response(int code, String message) {
        this.code = code;
        this.message = message;
    }

    // 成功响应, 默认消息
    public static <T> Response<T> success(T data) {
        return new Response<>(HttpStatus.OK.value(), "操作成功", data);
    }

    // 成功响应，自定义消息
    public static <T> Response<T> success(T data, String message) {
        return new Response<>(HttpStatus.OK.value(), message, data);
    }

    // 失败响应
    public static <T> Response<T> error(int code, String message) {
        return new Response<>(code, message);
    }
}
